package ru.isys.view;

import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.SpringLayout;

public class RequestResponsePanel extends JPanel
{
    ButtonGroup requestResponseButtonGroup;
    JRadioButton requestRadioButton;
    JRadioButton responseRadioButton;
    SpringLayout layout;
    
    public RequestResponsePanel(){
        System.out.println("Creating reqRespPanel");
        this.layout = new SpringLayout();
        this.setLayout(this.layout);        
        prepareButtons();
        setLayoutConstrains();
        this.validate();
    }
    
    private void setLayoutConstrains()
    {
        layout.putConstraint(SpringLayout.WEST, requestRadioButton, 10, SpringLayout.WEST, this);
        layout.putConstraint(SpringLayout.EAST, requestRadioButton, 0, SpringLayout.EAST, this);
        layout.putConstraint(SpringLayout.WEST, responseRadioButton, 0, SpringLayout.WEST, requestRadioButton);
        layout.putConstraint(SpringLayout.EAST, responseRadioButton, 0, SpringLayout.EAST, requestRadioButton);
        layout.putConstraint(SpringLayout.NORTH, requestRadioButton, 5, SpringLayout.NORTH, this);
        layout.putConstraint(SpringLayout.NORTH, responseRadioButton, 5, SpringLayout.SOUTH, requestRadioButton);        
    }

    private void prepareButtons(){
        requestResponseButtonGroup= new ButtonGroup();
        requestRadioButton= new JRadioButton("request");
        requestRadioButton.setActionCommand("request");
        
        responseRadioButton=new JRadioButton("response");
        responseRadioButton.setActionCommand("response");
        requestResponseButtonGroup.add(requestRadioButton);
        requestResponseButtonGroup.add(responseRadioButton);
        this.add(requestRadioButton);
        this.add(responseRadioButton);
     }
    
    public String getSelectedType(){
        return this.requestResponseButtonGroup.getSelection().getActionCommand();
    }
}
